﻿namespace Sidvall.LogManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class UserConfiguration : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.LogManager.Data.IUserConfiguration
    {
        #region Public Members

        #region Name

        private string _Name;
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        { 
            get
            {
                return _Name;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Name = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                    OnBeforeNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Name", eventData.Value, true, true);
                        OnAfterNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ShowNewsAtStartup

        private bool _ShowNewsAtStartup;
        partial void OnBeforeShowNewsAtStartupPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterShowNewsAtStartupPropertyChanged();
        public bool ShowNewsAtStartup
        { 
            get
            {
                return _ShowNewsAtStartup;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ShowNewsAtStartup = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _ShowNewsAtStartup);
                    OnBeforeShowNewsAtStartupPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ShowNewsAtStartup", eventData.Value, true, true);
                        OnAfterShowNewsAtStartupPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region StartPageId

        private global::Sidvall.LogManager.Data.PageType _StartPageId;
        partial void OnBeforeStartPageIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.LogManager.Data.PageType> eventData);
        partial void OnAfterStartPageIdPropertyChanged();
        public global::Sidvall.LogManager.Data.PageType StartPageId
        { 
            get
            {
                return _StartPageId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _StartPageId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.LogManager.Data.PageType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.LogManager.Data.PageType>(value, _StartPageId);
                    OnBeforeStartPageIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("StartPageId", eventData.Value, true, true);
                        OnAfterStartPageIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region STSAddress

        private string _STSAddress;
        partial void OnBeforeSTSAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSAddressPropertyChanged();
        public string STSAddress
        { 
            get
            {
                return _STSAddress;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _STSAddress = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSAddress);
                    OnBeforeSTSAddressPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("STSAddress", eventData.Value, true, true);
                        OnAfterSTSAddressPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region STSClientId

        private string _STSClientId;
        partial void OnBeforeSTSClientIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientIdPropertyChanged();
        public string STSClientId
        { 
            get
            {
                return _STSClientId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _STSClientId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientId);
                    OnBeforeSTSClientIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("STSClientId", eventData.Value, true, true);
                        OnAfterSTSClientIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region STSClientSecret

        private string _STSClientSecret;
        partial void OnBeforeSTSClientSecretPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientSecretPropertyChanged();
        public string STSClientSecret
        { 
            get
            {
                return _STSClientSecret;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _STSClientSecret = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientSecret);
                    OnBeforeSTSClientSecretPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("STSClientSecret", eventData.Value, true, true);
                        OnAfterSTSClientSecretPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region TwoFactorProvider

        private System.Nullable<Sidvall.Security.TwoFactorProvider> _TwoFactorProvider;
        partial void OnBeforeTwoFactorProviderPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<Sidvall.Security.TwoFactorProvider>> eventData);
        partial void OnAfterTwoFactorProviderPropertyChanged();
        public System.Nullable<Sidvall.Security.TwoFactorProvider> TwoFactorProvider
        { 
            get
            {
                return _TwoFactorProvider;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _TwoFactorProvider = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<Sidvall.Security.TwoFactorProvider>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<Sidvall.Security.TwoFactorProvider>>(value, _TwoFactorProvider);
                    OnBeforeTwoFactorProviderPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("TwoFactorProvider", eventData.Value, true, true);
                        OnAfterTwoFactorProviderPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserConfigurationId

        private System.Nullable<int> _UserConfigurationId;
        partial void OnBeforeUserConfigurationIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterUserConfigurationIdPropertyChanged();
        public System.Nullable<int> UserConfigurationId
        { 
            get
            {
                return _UserConfigurationId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserConfigurationId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _UserConfigurationId);
                    OnBeforeUserConfigurationIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserConfigurationId", eventData.Value, true, true);
                        OnAfterUserConfigurationIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public ServerConnectionCollectionItem ServerConnections { get; set; }
        #region LoadServerConnections

        public void LoadServerConnections(ServerConnectionCollectionItem value)
        {
            LoadInstanceField("ServerConnections", value, true, false);
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public UserConfiguration Copy()
        {
            return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Copy(this);
        }
        public UserConfiguration Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.LogManager.Data.IUserConfiguration item)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Import(this, item);
        }
        public void Import(global::Sidvall.LogManager.Data.IUserConfiguration item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Initialize(this, settings);
        }

        #endregion

        #region IUserConfiguration Members

        string global::Sidvall.LogManager.Data.IUserConfiguration.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        bool global::Sidvall.LogManager.Data.IUserConfiguration.ShowNewsAtStartup
        {
            get
            {
                return this._ShowNewsAtStartup;
            }
            set
            {
                this._ShowNewsAtStartup = value;
            }
        }
        global::Sidvall.LogManager.Data.PageType global::Sidvall.LogManager.Data.IUserConfiguration.StartPageId
        {
            get
            {
                return this._StartPageId;
            }
            set
            {
                this._StartPageId = value;
            }
        }
        string global::Sidvall.LogManager.Data.IUserConfiguration.STSAddress
        {
            get
            {
                return this._STSAddress;
            }
            set
            {
                this._STSAddress = value;
            }
        }
        string global::Sidvall.LogManager.Data.IUserConfiguration.STSClientId
        {
            get
            {
                return this._STSClientId;
            }
            set
            {
                this._STSClientId = value;
            }
        }
        string global::Sidvall.LogManager.Data.IUserConfiguration.STSClientSecret
        {
            get
            {
                return this._STSClientSecret;
            }
            set
            {
                this._STSClientSecret = value;
            }
        }
        System.Nullable<Sidvall.Security.TwoFactorProvider> global::Sidvall.LogManager.Data.IUserConfiguration.TwoFactorProvider
        {
            get
            {
                return this._TwoFactorProvider;
            }
            set
            {
                this._TwoFactorProvider = value;
            }
        }
        System.Nullable<int> global::Sidvall.LogManager.Data.IUserConfiguration.UserConfigurationId
        {
            get
            {
                return this._UserConfigurationId;
            }
            set
            {
                this._UserConfigurationId = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.LogManager.Data.IServerConnection> global::Sidvall.LogManager.Data.IUserConfiguration.ServerConnections
        {
            get
            {
                if (this.ServerConnections != null)
                    return this.ServerConnections.Items;
                return null;
            }
        }
        void global::Sidvall.LogManager.Data.IUserConfiguration.SetServerConnections(Sidvall.Data.IDataRowProvider<global::Sidvall.LogManager.Data.IServerConnection> items)
        {
            this.ServerConnections = (ServerConnectionCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public UserConfiguration()
        {
        }
        public UserConfiguration(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public UserConfiguration(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.LogManager.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Initialize(this);
        }

        #endregion
    }
}